package domain

import (
	"gitee.com/linxing_3/sr-core/yerr"
	"gitee.com/mkwchecking/sr-admin/apps/devtools/acl"
	"github.com/spf13/cobra"
)

var (
	domainAddArg = &acl.DomainGenReq{}
	domainAddCmd = &cobra.Command{
		Use:     "add",
		Short:   "add domain",
		PreRunE: dependsCheck,
		RunE:    addDomainHandler,
	}
	cfg string
)

func init() {
	domainAddCmd.Flags().StringVarP(&domainAddArg.Domain, "domain", "d", "", "domain name")
	domainAddCmd.Flags().StringVarP(&domainAddArg.Description, "comment", "c", "", "domain comment")
	domainAddCmd.Flags().StringVarP(&cfg, "config", "f", "", "config file path")
}

func addDomainHandler(cmd *cobra.Command, args []string) error {
	if domainAddArg.Domain == "" {
		return yerr.ErrBizParamInvalid.Errorf("domain is required")
	}

	return svc.Domain.GenDomain(cmd.Context(), domainAddArg)
}
